e464f9
@@ -522,18 +522,23 @@
public class HFile {
       boolean isHBaseChecksum = fsdis.shouldUseHBaseChecksum();
       assert !isHBaseChecksum; // Initially we must read with FS checksum.
       trailer = FixedFileTrailer.readFromStream(fsdis.getStream(isHBaseChecksum), size);
-    } catch (IllegalArgumentException iae) {
-      throw new CorruptHFileException("Problem reading HFile Trailer from file " + path, iae);
-    }
-    switch (trailer.getMajorVersion()) {
-    case 2:
-      return new HFileReaderV2(
-          path, trailer, fsdis, size, cacheConf, preferredEncodingInCache, hfs);
-    case 3 :
-      return new HFileReaderV3(
-          path, trailer, fsdis, size, cacheConf, preferredEncodingInCache, hfs);
-    default:
-      throw new CorruptHFileException("Invalid HFile version " + trailer.getMajorVersion());
+      switch (trailer.getMajorVersion()) {
+      case 2:
+        return new HFileReaderV2(
+            path, trailer, fsdis, size, cacheConf, preferredEncodingInCache, hfs);
+      case 3 :
+        return new HFileReaderV3(
+            path, trailer, fsdis, size, cacheConf, preferredEncodingInCache, hfs);
+      default:
+        throw new IllegalArgumentException("Invalid HFile version " + trailer.getMajorVersion());
+      }
+    } catch (Throwable t) {
+      try {
+        fsdis.close();
+      } catch (Throwable t2) {
+        LOG.warn("Error closing fsdis FSDataInputStreamWrapper", t2);
+      }
+      throw new CorruptHFileException("Problem reading HFile Trailer from file " + path, t);
     }
   }
 
